﻿$(function () {
    CommonTree("ptype", "typeCode","showType");
    menuCode = getUrlVariable("menuCode");
    BannerData(menuCode, "bDiv", OthContent());
    
})
function OthContent() {
    var info = '<li class="layui-nav-item" style="float:left;padding-left:40px">' +
        '<label name = "showType" id = "showType" style = "color:#fff" >未选大类</label></li>';
    return info;
}
var inventory = '';
var menuCode = "";
/**
数据添加方法
**/
var id = ''
function addData() {
    if (typeCode != '') {
        var webUrl = '../Basis/UpdateInventoryInfo?dataId=0&typeCode=' + typeCode + '&inventory=' + inventory;
        var title = inventory + "-添加"
        var dUrl = "../Basis/GetDataList?dataType=ven&typesCode=" + typeCode
        NewOpenPage(webUrl, title, "65%", "80%", "InvTable", currPage, dUrl);
    } else {
        layer.msg("请先选择存货大类！");
    }
}
function SyncProduct() {
    SyncData("ven");
}
var currPage = 1
/**
 * 加载数据
 **/
function loadData() {
    layui.use('table', function () {
        var conditon = JSON.stringify(FormToJson("qForm"));
        var table = layui.table;
        dUrl = "../Basic/getDataList?condition=" + conditon + "&dataType=ven&typesCode=" + typeCode;
        table.render({
            elem: '#list'
            , cols: [[ //标题栏
                { field: 'proCode', title: '存货编码', width: 140 }
                , { field: 'proName', title: '存货名称', width: 170 }
                , { field: 'spec', title: '规格型号', width: 150 }
                , { field: 'isSyncName', title: '同步数据', width: 100 }
                , { field: 'statusName', title: '是否启用', width: 100 }
                //, {  title: '操作', width: 90, align: 'center', toolbar: '#barDemo' }
            ]], done: function (res, curr, count) {
                currPage = curr
                TablePowerHide();
                $.each(res['data'], function (i, obj) {
                    var status = obj["status"];
                    if (status == "close") {
                        TableRowColor('layui-table-main', i, '#ffd800');
                    }
                });
            }
            , url: dUrl
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [15, 30, 50]
            , limit: 15 //每页默认显示的数量
            , id: "InvTable"
        });

        table.on('tool(list)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent == 'icEdit') {
                if (data.isSync == "Y") {
                    layer.msg("同步数据禁止修改");
                } else {
                    id = data.id
                    var webUrl = '../Basis/UpdateInventoryInfo?dataId=' + data.id + '&inventory=' + inventory;
                    var title = data.proName + "-修改"
                    NewOpenPage(webUrl, title, "65%", "80%", "InvTable", currPage, dUrl);
                }
            } else if (layEvent == 'icDel') {
                if (data.isSync == "Y") {
                    layer.msg("同步数据禁止删除");
                } else {
                    layer.confirm('确定删除该档案？', function (index) {
                        $.ajax({
                            url: "../Basis/DelInventoryInfo",
                            data: { dataId: data.id },
                            type: 'post',
                            success: function (rsl) {
                                if (rsl.Result) {
                                    layer.msg('删除成功！');
                                } else {
                                    layer.msg('删除失败！');
                                }
                                //console.log(typeCode)
                                loadData(typeCode)
                            }
                        })
                        layer.close('index')
                    })
                }
            }
        });

    });
}

/**
 数据同步方法
 **/
function syncData() {
    var index = layer.load(1, { shade: [0.7, '#393D49'] }, { shadeClose: true }); //0代表加载的风格，支持0-2
    $.ajax({
        url: "../System/SyncData",
        data: { syncCode: "ven" },
        dataType: "json",
        type: "POST",
        success: function (rsl) {
            if (rsl.result) {
                layer.msg("同步执行成功");
            } else {
                layer.msg(data.message);
            }
            layer.close(index);
        }
    });
}